extern "C" void putch(int ch);
extern "C" void putch1(int ch);
extern "C" void uart0Putch(int ch);
extern "C" void swi_funct(int ch);

void putch(int ch)
{
register int a asm ("r0");
a = ch;
asm("stmfd sp!,{lr}");
asm("mrs r2,spsr");
asm("stmfd sp!,{r2}");
asm volatile("swi #3" ::: "r0");
asm("ldmfd sp!,{r2}");
asm("msr spsr, r2");
asm("ldmfd sp!,{lr}");
}

void putch1(int ch)
{
register int a asm ("r0");
a = ch;
asm("stmfd sp!,{lr}");
asm("mrs r2,spsr");
asm("stmfd sp!,{r2}");
asm volatile("swi #1" ::: "r0");
asm("ldmfd sp!,{r2}");
asm("msr spsr, r2");
asm("ldmfd sp!,{lr}");
}

int save_last_char = 0;

void swi_funct(int ch)
{
   register int *a asm ("r14");
//   int *a = get_r14();
    switch (*(a-1) & 0x00ffffff)
    {
    case 1:
      uart0Putch('1');
      break;
    case 2:
      uart0Putch('2');
      break;
    case 3:
      uart0Putch('3');
      break;
    default:
      uart0Putch('?');
    }
   save_last_char = ch;
    uart0Putch(ch);
}
void swi_funct(int) __attribute__ ((interrupt("SWI")));
